import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 输入两行数据
        String zInput = scanner.nextLine();
        String wInput = scanner.nextLine();

        // 解析两位教授的行程数据
        Map<String, Integer> zMap = parseTravelData(zInput.split(":")[1]);
        Map<String, Integer> wMap = parseTravelData(wInput.split(":")[1]);

        // 找出共同去过的城市
        List<String> commonCities = new ArrayList<>();
        for (String city : zMap.keySet()) {
            if (wMap.containsKey(city)) {
                commonCities.add(city);
            }
        }

        // 如果没有共同城市，输出 "none"
        if (commonCities.isEmpty()) {
            System.out.println("none");
            return;
        }

        // 对共同城市按字母升序排序
        Collections.sort(commonCities);

        // 构造输出结果
        StringBuilder result = new StringBuilder();
        for (String city : commonCities) {
            int zDays = zMap.get(city);
            int wDays = wMap.get(city);

            if (zDays > wDays) {
                result.append("z:").append(city).append(" ").append(zDays).append(",");
            } else {
                result.append("w:").append(city).append(" ").append(wDays).append(",");
            }
        }

        // 去掉最后一个多余的逗号
        result.deleteCharAt(result.length() - 1);

        // 输出结果
        System.out.println(result.toString());

        scanner.close();
    }

    /**
     * 解析行程数据为城市-天数的映射表
     *
     * @param data 行程数据字符串
     * @return 城市-天数的映射表
     */
    private static Map<String, Integer> parseTravelData(String data) {
        Map<String, Integer> travelMap = new HashMap<>();
        String[] groups = data.split(",");

        for (String group : groups) {
            String[] parts = group.trim().split(" ");
            String city = parts[0];
            int days = Integer.parseInt(parts[1]);

            // 累加同一城市的天数
            travelMap.put(city, travelMap.getOrDefault(city, 0) + days);
        }

        return travelMap;
    }
}